{extend name="../public/header" /}
{block name="body"}
<body>
{include file="../public/common" /}
<fieldset class="layui-elem-field site-demo-button" style="padding:10px;">
	<div class="layui-row">
		<!--  -->
		<form id="form1" class="layui-form layui-form-pane" action="{:url('')}">
			<section class="panel panel-padding">
				<div class="layui-form-item">
					<label class="layui-form-label">名称</label>
					<div class="layui-input-inline">
						<input type="text" name="bossname" value="{$info.bossname|default=''}" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">介绍</label>
					<div class="layui-input-inline">
						<textarea name="bossinfo" placeholder="请输入介绍" class="layui-textarea">{$info.bossinfo|default=''}</textarea>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">等级</label>
					<div class="layui-input-inline">
						<input type="text" name="bosslv" value="{$info.bosslv|default='0'}" class="layui-input">
					</div>
				</div>
				<fieldset class="layui-elem-field">
					<legend>属性</legend>
					<div class="layui-field-box">
						<div class="layui-row">
							<div class="layui-form-item">
								<label class="layui-form-label">生命</label>
								<div class="layui-input-inline" style="width:83px;">
									<input type="text" name="bosshp" value="{$info.bosshp|default='0'}" placeholder="0" autocomplete="off" class="layui-input">
								</div>
								<div class="layui-form-mid">-</div>
								<div class="layui-input-inline" style="width:83px;">
									<input type="text" name="bossmaxhp" value="{$info.bossmaxhp|default='0'}" placeholder="0" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">攻击</label>
								<div class="layui-input-inline">
									<input type="text" name="bossgj" value="{$info.bossgj|default='0'}" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">防御</label>
								<div class="layui-input-inline">
									<input type="text" name="bossfy" value="{$info.bossfy|default='0'}" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">暴击</label>
								<div class="layui-input-inline">
									<input type="text" name="bossbj" value="{$info.bossbj|default='0'}" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">吸血</label>
								<div class="layui-input-inline">
									<input type="text" name="bossxx" value="{$info.bossxx|default='0'}" class="layui-input">
								</div>
							</div>
						</div>
					</div>
				</fieldset>
				<!-- / -->
				<fieldset class="layui-elem-field">
					<legend>掉落装备</legend>
					<div class="layui-field-box">
						<div class="layui-row" id="bosszb">
							<div class="layui-form-item">
								<label class="layui-form-label">道具</label>
								<button class="layui-btn ajax-mold" data-url="{:url('getMoldList')}" data-type="1" type="button">新增</button>
							</div>
							{foreach name='info.zb_list' item='vo'}
							<div class="layui-form-item">
								<label class="layui-form-label">ID</label>
								<div class="layui-input-inline">
									<input name="bosszb[{$key}][id]" value="{$vo.id}" placeholder="请输入" class="layui-input" type="text">
								</div>
								<label class="layui-form-label">名称</label>
								<div class="layui-input-inline">
									<input name="bosszb[{$key}][name]" value="[lv:{$vo.lv}]{$vo.name}" placeholder="请输入" class="layui-input" type="text">
								</div>
								<button class="layui-btn layui-btn-danger" onclick="delNum(this,1)" type="button">-</button>
							</div>
							{/foreach}
						</div>
					</div>
				</fieldset>
				<!-- / -->
				<fieldset class="layui-elem-field">
					<legend>掉落道具</legend>
					<div class="layui-field-box">
						<div class="layui-row" id="bossdj">
							<div class="layui-form-item">
								<label class="layui-form-label">道具</label>
								<button class="layui-btn ajax-mold" data-url="{:url('getMoldList')}" data-type="2" type="button">新增</button>
							</div>
							{foreach name='info.dj_list' item='vo'}
							<div class="layui-form-item">
								<label class="layui-form-label">ID</label>
								<div class="layui-input-inline">
									<input name="bossdj[{$key}][id]" value="{$vo.id}" placeholder="请输入" class="layui-input" type="text">
								</div>
								<label class="layui-form-label">名称</label>
								<div class="layui-input-inline">
									<input name="bossdj[{$key}][name]" value="{$vo.name}" placeholder="请输入" class="layui-input" type="text">
								</div>
								<button class="layui-btn layui-btn-danger" onclick="delNum(this,2)" type="button">-</button>
							</div>
							{/foreach}
						</div>
					</div>
				</fieldset>
				<!-- / -->
				<div class="layui-form-item">
					<label class="layui-form-label">刷新时间</label>
					<div class="layui-input-inline">
						<input type="text" id="bosstime" name="bosstime" value="{$info.bosstime|default=''}" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">刷新间隔</label>
					<div class="layui-input-inline">
						<input type="text" name="bs" value="{$info.bs|default='0'}" class="layui-input">
					</div>
					<div class="layui-form-mid layui-word-aux">单位:秒</div>
				</div>
				<!-- / -->

				<div class="layui-input-block">
					<input type="hidden" name="bossid" type="hidden" value="{$info.bossid|default=''}">
					<button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</section>
		</form>
		<!--  -->
	</div>
</fieldset>
</body>
{/block}
{block name="script"}
<script>
layui.use(['jquery','form','laydate','upload','element'], function(){
	var $ = layui.jquery
	,laydate = layui.laydate
	,upload = layui.upload
	,element = layui.element
	,form = layui.form;

	laydate.render({
		elem: '#bosstime'
		,type: 'datetime'
	});

	$('.ajax-mold').on('click',function(){
		var obj = $(this);
		var url = obj.data('url');
		var type = obj.data('type');
		var title = obj.data('title');

		url = url + '?type=' + type;
		console.log('url',url);

		layer.open({
			type: 2,
			title: title,
			shadeClose: true, //是否点击遮罩关闭 默认：false
			maxmin: false, //开启最大化最小化按钮 默认：false
			area: ['500px', '400px'],
			content: url,
			btn: ['确定', '取消'],
			yes: function (index, layero) {
				var n = $(layero).find('iframe')[0];
				var objb = $(n).contents().find("select[name='mold'] option:selected");
				var id = $(objb).val();
				var text = $(objb).text();

				console.log('id',id);
				console.log('name',text);
				console.log('type',type);

				addHtml(id,text,type);

				layer.close(index);
			},
			btn2: function (index, layero) {
				layer.close(index);
			},
			cancel: function () {
				//右上角关闭回调
				return true //开启该代码可禁止点击该按钮关闭
			}
		});
	});

	form.render();
});
</script>
<script>
	var zb_list = "{$zb_list|default='1'}";
	var dj_list = "{$dj_list|default='1'}";

	layui.use(['jquery','form'], function(){
		var $ = layui.jquery
				,form = layui.form;

		window.addHtml = function(id,name,type) {
			var selector = '';
			var key = 1;
			if(type===1){key = zb_list;selector = 'bosszb';}
			if(type===2){key = dj_list;selector = 'bossdj';}

			$("#"+selector).append(
					"<div class='layui-form-item'>" +
					"<label class='layui-form-label'>ID</label>" +
					"<div class='layui-input-inline'>" +
					"<input type='text' name='"+selector+"["+key+"][id]' value='"+id+"' placeholder='请输入' class='layui-input'>" +
					"</div>" +
					"<label class='layui-form-label'>名称</label>" +
					"<div class='layui-input-inline'>" +
					"<input type='text' name='"+selector+"["+key+"][name]' value='"+name+"' placeholder='请输入' class='layui-input'>" +
					"</div>" +
					"<button class='layui-btn layui-btn-danger' onclick='delNum(this,"+type+")' type='button'>-</button>" +
					"</div>");

			if(type===1){zb_list++;}
			if(type===2){dj_list++;}
		}

	});

	function delNum(obj,type) {
		var $ = layui.jquery;
		$(obj).parent().remove();

		if(type===1){zb_list--;}
		if(type===2){dj_list--;}
	}
</script>
{/block}